﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityComponentSystem.Framework;
using EntityComponentSystem.Framework.Math;
using EntityComponentSystem.Demos.SpaceAttack.Systems;

namespace EntityComponentSystem.Demos.SpaceAttack.Components
{
    //public interface IPositionComponent : IComponent
    //{
    //    IVector3d Position { get; set; }
    //}
    public struct PositionEvent : IEvent
    {
        public Vector2 oldPosition;
        public PositionComponent Position;
    }

    public class PositionComponent : Component<Vector2>//, IPositionComponent
    {

        protected override void OnInit()
        {
            base.OnInit();
            Value = new Vector2(500, 500);
            
        }

        public void Set(Vector2 amount)
        {
            if (Value != amount)
            {
                var oldValue = Value;
                Value = amount;
                this.Entity.Dispatch(new PositionEvent() { oldPosition = oldValue, Position = this });
            }
        }

        public void Add(Vector2 amount)
        {
            Set(Value += amount);            
        }
    }
}
    